#include <rclcpp/rclcpp.hpp>
#include <std_msgs/msg/string.hpp>

class SubscriperOnceDataNode : public rclcpp::Node {
public:
  SubscriperOnceDataNode(std::string node_name) : rclcpp::Node(node_name) {
    RCLCPP_INFO(this->get_logger(), "node: %s", node_name.c_str());
    subscription_ = this->create_subscription<std_msgs::msg::String>(
        "topic_once", 10,
        std::bind(&SubscriperOnceDataNode::topic_callback, this,
                  std::placeholders::_1));
  }

  void topic_callback(const std_msgs::msg::String::SharedPtr msg) {
    RCLCPP_INFO(this->get_logger(), "Received message: %s", msg->data.c_str());
  }

private:
  rclcpp::Subscription<std_msgs::msg::String>::SharedPtr subscription_;
};

int main(int argc, char *argv[]) {
  rclcpp::init(argc, argv);
  rclcpp::spin(
      std::make_shared<SubscriperOnceDataNode>("subscriper_once_data_node"));
  rclcpp::shutdown();
  return 0;
}